<template>
	<view class="content">
		<image :src="imgoss+pic" class="logo" mode="aspectFill"></image>
		<view class="logincon">
			<view class="title">您好,欢迎登录~</view>
			<view class="txt">
				<image src="/static/conimg2.png" class="conimg" mode="widthFix"></image>
				<input v-model="phone" type="text" placeholder="请输入账号" />
			</view>
			<view class="txt txts1" style="margin-bottom: 10px;">
				<image src="/static/conimg3.png" class="conimg" mode="widthFix"></image>
				<input v-model="code" type="password" placeholder="请输入密码" />
				<!-- <view class="txt3" @tap="sendCode">{{sendTime}}</view> -->
			</view>
			<!-- <view class="txt1" @tap="jump">忘记密码？</view> -->
			<view class="login" @tap="save">登录</view>
			<!-- <view class="look">
		   	<view>
		   		<checkbox-group @change="checkboxChange">
		   			<label>
		   				<checkbox :checked="ischecked" value="1" color="#CB1717" style="transform:scale(0.7)" />
		   				已阅读并同意
		   			</label>
		   		</checkbox-group>
		   	</view><text @tap="jump('/subcontract/xydes/xydes?type=fw')">《服务协议》</text>和<text @tap="jump('/subcontract/xydes/xydes?type=ys')">《隐私协议》</text>
		   </view> -->
		</view>
	</view>
</template>

<script>
	var util = require('../../utils/util.js');
	const app = getApp();
	export default {
		data() {
			return {
				id: 0,
				img_src: app.globalData.img_src,
				img_url: app.globalData.img_urls,
				phone: '',
				code: '',
				imgoss: app.globalData.imgoss,
				pic: '',
				sendTime: '获取验证码',
				sendColor: '#363636',
				snsMsgWait: 60,
				ischecked: false
			};
		}
		/**
		 * 生命周期函数--监听页面加载
		 */
		,
		onLoad(options) {
			var that = this;
			// if (util.isWechat() == true) {
			// 	uni.showModal({
			// 		content: '请同意微信授权',
			// 		showCancel: false,
			// 		success: function(res) {
			// 			if (res.confirm) {
			// 				uni.navigateTo({
			// 					// 跳转授权链接
			// 					 url: '/pages/externalPage/externalPage'
			// 				});
			// 			}
			// 		}
			// 	})
			// }
		
		},
		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady() {},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow() {
			app.globalData.api.request('Index/index', {
				official_id:uni.getStorageSync('official_id'),
				// channel_id: uni.getStorageSync('channel_id'),
				// channel_url_id: uni.getStorageSync('channel_url_id'),
				// channel_user_id: uni.getStorageSync('channel_user_id'),
			}, 'POST', 'form').then((res) => {
				if (res.code == 0) {
					//console.log(res)
					this.pic = res.data.pic
					// uni.setNavigationBarTitle({
					// 	title: res.data.name,
					// 	success: () => {
					// 		////console.log('修改标题成功')
					// 	},
					// 	fail: () => {
					// 		////console.log('修改标题失败')
					// 	},
					// 	complete: () => {
					// 		////console.log('修改标题结束')
					// 	},
					// })

				} else {
					app.globalData.show(res.msg)
				}
			});
			// app.globalData.api.request('Index/gs', {
			// }, 'POST', 'form').then((res) => {
			// 	if (res.code == 0) {
			// 		//console.log(res)
			// 		this.pic = res.data.pic
			// 	}else{
			// 		app.globalData.show(res.msg)
			// 	}
			// });
		},
		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide() {},
		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload() {},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh() {},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom() {},
		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage() {},
		methods: {
			jump(url) {
				uni.navigateTo({
					url: url
				})
			},
			// 获取验证码
			sendCode: function() {
				var that = this;
				if (!this.smsFlag) {
					if (this.phone == "") {
						app.globalData.show('请输入手机号');
						return;
					}
					// /^1(3[0-9]|4[5,7]|5[0,1,2,3,5,6,7,8,9]|6[2,5,6,7]|7[0,1,7,8,6]|8[0-9]|9[1,8,9])\d{8}$/
					if (this.phone.length != 11) {
						app.globalData.show('手机号输入错误');
						return;
					}

					// 60秒后重新获取验证码
					var inter = setInterval(function() {
						this.smsFlag = true
						this.sendColor = '#cccccc'
						this.sendTime = this.snsMsgWait + 's后重发'
						this.snsMsgWait = this.snsMsgWait - 1
						if (this.snsMsgWait < 0) {
							clearInterval(inter)
							this.sendColor = '#363636'
							this.sendTime = '发送验证码'
							this.snsMsgWait = 60
							this.smsFlag = false
						}
					}.bind(this), 1000);
					app.globalData.api.request('index/getsm', {
						phone: this.phone
					}, 'POST', 'form').then((res) => {
						if (res.code == 0) {} else {
							app.globalData.show(res.msg)
						}
					});
				}

			},
			checkboxChange: function(e) {
				var values = e.detail.value;
				if (values.length > 0) {
					this.ischecked = true;
				} else {
					this.ischecked = false;
				}
			},
			save() {
				if (this.phone == '') {
					app.globalData.show('请输入账号~')
					return true
				}
				// if(!(/^1(3[0-9]|4[5,7]|5[0,1,2,3,5,6,7,8,9]|6[2,5,6,7]|7[0,1,7,8,6]|8[0-9]|9[1,8,9])\d{8}$/.test(this.phone))){
				// 	app.globalData.show('请手机格式错误~')
				// 	return true
				// }

				if (this.code == '') {
					app.globalData.show('请输入密码~')
					return true
				}
				const that = this;
				app.globalData.api.request('Shop/login', {
					username: that.phone,
					pwd: that.code,
				}, 'POST', 'form').then((res) => {
					if (res.code == 0) {
						//console.log(res)
						uni.setStorageSync('sjtype', 1);
						uni.setStorageSync('sjtypes', 1);
						uni.setStorageSync('sjtoken', res.data.token_shop);
						uni.showToast({
							title: '登录成功~',
							icon: 'none',
							duration: 2000,
							success: function() {
								setTimeout(function() {
									uni.reLaunch({
										url: '/pages/order/billList'
									})
								}, 1000);
							}
						});
					} else {
						app.globalData.show(res.msg)
					}
				});

			}
		}
	};
</script>
<style lang="scss">
	.txt3 {
		width: 152rpx !important;
		height: 62rpx !important;
		background: #fff;
		border-radius: 4rpx;
		text-align: center;
		line-height: 62rpx;
		position: absolute;
		top: 50%;
		right: 0rpx !important;
		margin-top: -31rpx !important;
		font-family: PingFang SC;
		font-weight: 400;
		font-size: 24rpx !important;
		color: #8665AF !important;
	}

	.txts1 {
		position: relative;
		box-sizing: border-box;
		padding-right: 70px;
	}

	.look {
		font-weight: 400;
		font-size: 28rpx;
		color: #727272;
		text-align: center;
	}

	.look>view:nth-child(1) {
		display: inline-block;
	}


	.look text {
		color: #3689EA;
	}

	.title {
		width: 100%;
		height: auto;
		color: rgb(53, 53, 53);
		font-size: 36rpx;
		font-family: PingFangSC-regular;
		box-sizing: border-box;
		padding: 37rpx;
	}

	.logo {
		width: 132rpx;
		height: 132rpx;
		display: table;
		border-radius: 10rpx;
		margin: 52rpx auto;
	}

	.imgtop {
		width: 100%;
		height: auto;
	}

	.txt2>span {
		position: relative;
	}

	.txt2 {
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 500;
		font-size: 48rpx;
		color: #000000;
		width: 686rpx;
		height: auto;
		display: table;
		margin-left: 32rpx;
		margin-top: 70rpx;
		position: relative;
	}

	.txt2::before {
		content: "";
		width: 96rpx;
		height: 10rpx;
		background-color: #0066ff;
		position: absolute;
		left: 0px;
		bottom: 0px;
	}

	.txt3 {
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 500;
		font-size: 40rpx;
		color: #999999;
		width: 686rpx;
		height: auto;
		display: table;
		margin-left: 32rpx;
		margin-top: 30rpx;
		margin-bottom: 80rpx;
	}

	.login {
		width: 621rpx;
		height: 92rpx;
		background: linear-gradient(89.88deg, rgba(157, 102, 171, 1) 3.4%, rgba(118, 100, 177, 1) 99.4%);
		border-radius: 46rpx;
		text-align: center;
		line-height: 92rpx;
		font-family: Source Han Sans SC;
		font-weight: 400;
		font-size: 32rpx;
		color: #FFFFFF;
		margin: 223rpx auto;
	}

	.txt1 {
		width: 601rpx;
		height: auto;
		display: table;
		margin: 0px auto;
		font-family: Source Han Sans SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #C9C9C9;
		text-align: right;
	}

	.txt>input {
		width: 100%;
		height: 80rpx;
		font-family: Source Han Sans SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #222;
	}

	.conimg {
		width: 23px;
		height: auto;
		display: table;
		position: absolute;
		top: 50%;
		left: 5px;
		margin-top: -10px;
	}

	.txt {
		width: 601rpx;
		display: table;
		margin: auto;
		height: 80rpx;
		position: relative;
		padding-left: 35px;
		box-sizing: border-box;
		border-bottom: 1px solid #E5E5E5;
		margin-bottom: 60rpx;
	}

	.logincon {
		width: 702rpx;
		min-height: 700rpx;
		background: #FFFFFF;
		border-radius: 36rpx;
		margin: 40px 24rpx;
		padding: 80rpx 0px;
		padding-top: 20rpx;
		background-color: rgba(255, 255, 255, 1);
		box-shadow: 0px 2px 6px 5px rgba(0, 0, 0, 0.07);
	}

	page {
		background-color: #fff;
	}

	.content {
		width: 100%;
		height: 100vh;
		display: table;
		background: url($IMG_URL+'imgtop.png')no-repeat;
		background-size: 100% auto;
		background-position: top left;
	}
</style>